package org.budo.ocr.service.util;

import org.budo.ocr.service.api.BudoOcrService;
import org.budo.ocr.service.api.OcrResponse;
import org.budo.ocr.service.impl.ByteArrayOcrRequest;
import org.budo.support.java.awt.robot.BudoImage;
import org.budo.support.lang.util.StringUtil;

/**
 * @author limingwei
 */
public class OcrUtil {
    public static String ocr(BudoOcrService ocrService, BudoImage image) {
        ByteArrayOcrRequest ocrRequest = new ByteArrayOcrRequest(image.toPng());
        OcrResponse ocrResponse = ocrService.recognition(ocrRequest);

        if (null == ocrResponse) {
            return null;
        }

        return StringUtil.join(ocrResponse.getWords());
    }
}